﻿using HMS.DataContact.Response;
using HMS.DataContract.Request;
using HMS.DataContract.Response;
using HMS.Facade;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Web.Script.Serialization;

//using Newtonsoft.Json;
namespace HMS.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Scheduler" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Scheduler.svc or Scheduler.svc.cs at the Solution Explorer and start debugging.
    public class Scheduler : IScheduler
    {

        public List<DoctorResponse> GetDoctorList(int LocId)
        {
            ServiceFacade _service = new ServiceFacade();
            List<DoctorResponse> lstLookup = new List<DoctorResponse>();
            var lstDoctor = _service.GetDoctorList(LocId);
            return lstDoctor;
        }

        //public string GetLocationList() {
        //    ServiceFacade _service = new ServiceFacade();
        //    List<LocationResponse> lstLookup = new List<LocationResponse>();
        //    var lstLocation = _service.GetLocationList();

        //    return JsonConvert.SerializeObject(lstLocation) ;
        //}
        public List<LocationResponse> GetLocationList(string clinicCode) {
            ServiceFacade _service = new ServiceFacade();
            return _service.GetLocationList(clinicCode);
        }

        public List<DoctorAppointmentResponse> GetAppointmentDetails(int patientId, int doctorApptId, int doctorId)
        {
            ServiceFacade _service = new ServiceFacade();
            DoctorAppointmentResponse doctorAppointmentResponse = new DoctorAppointmentResponse();
            return _service.GetAppointmentDetails(patientId,doctorApptId,doctorId);
            //if (appointmentDetails != null)
            //{
            //    doctorAppointmentResponse.Id = appointmentDetails.Id;
            //    doctorAppointmentResponse.DocLocId = appointmentDetails.DocLocId;
            //    doctorAppointmentResponse.Patient = new PatientResponse()
            //    {
            //        Id = appointmentDetails.Patient.Id,
            //        Name = appointmentDetails.Patient.Name,
            //        Gender = appointmentDetails.Patient.Gender,
            //        DOB = appointmentDetails.Patient.DOB,
            //        //Clinic
            //        Allergies = appointmentDetails.Patient.Allergies,
            //        Phone = appointmentDetails.Patient.Phone,
            //        Email = appointmentDetails.Patient.Email
            //    };
            //    doctorAppointmentResponse.AppointmentDateTime = appointmentDetails.AppointmentDateTime;
            //    doctorAppointmentResponse.FollowUpStatus = appointmentDetails.FollowUpStatus;
            //    doctorAppointmentResponse.Purpose = appointmentDetails.Purpose;
            //    doctorAppointmentResponse.AppointmentStatus = appointmentDetails.AppointmentStatus;
            //}
            //return doctorAppointmentResponse;
        }

        public List<MonthChart> GetMonthlyAppointmentList(int DocId, int LocId,int clinicId, DateTime startDate, DateTime endDate)
        {

            ServiceFacade _serviceFacade = new ServiceFacade();
            var _lstAppointment = _serviceFacade.GetMonthlyAppointmentList(DocId, LocId,clinicId, startDate, endDate);
            return _lstAppointment;
        }

        public List<DailyList> GetDailyAppointmentList(int DocId, int LocId, int clinicId, DateTime startDate, DateTime endDate)
        {

            ServiceFacade _serviceFacade = new ServiceFacade();
            var _lstAppointment = _serviceFacade.GetDailyAppointmentList(DocId, LocId,clinicId, startDate, endDate);
            return _lstAppointment;
        }
        public DoctorAppointmentResponse SaveAppointmentDetails(DoctorAppointmentResponse doctorAppointmentResponse, string clinicCode)
        {
            ServiceFacade _service = new ServiceFacade();
            return _service.SaveAppointmentDetails(doctorAppointmentResponse, clinicCode);
        }

        public ClinicResponse GetClinicName(string clinicCode)
        {
            ServiceFacade _service = new ServiceFacade();
            
               
            return _service.GetClinicName(clinicCode);
        }

        public DoctorAppointmentResponse DeleteAppointment(int AppointmentId)
        {
            ServiceFacade _service = new ServiceFacade();
            return _service.DeleteAppointment(AppointmentId);
        }

        public List<PatientResponse> GetPatientList(string PatientName,int ClinicId)
        {
            ServiceFacade _service = new ServiceFacade();
            return _service.GetPatientName(PatientName, ClinicId);
        }

        public DoctorAppointmentResponse GetPatientById(int PatientId,DateTime date)
        {
            ServiceFacade _serviceFacade = new ServiceFacade();
            return _serviceFacade.GetPatientById(PatientId, date);
        }

        public AppointmentDocumentResponse SaveImage(AppointmentDocumentRequest appDoc)
        {
            ServiceFacade _serviceFacade = new ServiceFacade();
            return _serviceFacade.SaveImage(appDoc);
        }


        public UserInfo ValidateUser(string accessCode) 
        {
            UserFacade userFacade = new UserFacade();
            return userFacade.ValidateUser(accessCode);
        }

        public List<AppointmentDocumentResponse> GetImageList(int DocApptId) {
            ServiceFacade service = new ServiceFacade();
            return service.GetImageList(DocApptId);
        }

        public List<DoctorAppointmentResponse> GetAppointmentHistoryByPatientId(int patientId, int numberOfRecord)
        {
            ServiceFacade service = new ServiceFacade();
            return service.GetAppointmentHistoryByPatientId(patientId, numberOfRecord);
        }

        public int SavePatientDetails(PatientResponse patient)
        {
            ServiceFacade service = new ServiceFacade();
            return service.SavePatientDetails(patient);
        }

        public AppointmentDocumentResponse SavePatientImage(AppointmentDocumentRequest appDoc)
        {
            ServiceFacade _serviceFacade = new ServiceFacade();
            return _serviceFacade.SavePatientImage(appDoc);
        }

        public List<TimeSpan> GetDoctorSlots(int DocId)
        {
            ServiceFacade service = new ServiceFacade();
            return service.GetDoctorSlots(DocId);
        }

        public List<DateTime> GetDoctorDayOffList(int DocId,DateTime startDate, DateTime endDate)
        {
            ServiceFacade service = new ServiceFacade();
            return service.GetDoctorDayOffList(DocId, startDate, endDate);
        }

        public DoctorAppointmentResponse GetAppointmentbyId(int DocAppId) {
            ServiceFacade service = new ServiceFacade();
            return service.GetAppointmentById(DocAppId);
        }

        public List<DoctorAppointmentResponse> GetAppointmentbyPatientId(int PatientId)
        {
            ServiceFacade _service = new ServiceFacade();
            return _service.GetApptbyPatientId(PatientId);
        }

        public bool SavePrescriptionText(AppointmentDocumentRequest appDoc) {
            ServiceFacade _serviceFacade = new ServiceFacade();
            return  _serviceFacade.SavePrescriptionText(appDoc);
        }

        public bool SaveDoctorDayOff(int DocId, DateTime date)
        {
            ServiceFacade _serviceFacade = new ServiceFacade();
            return _serviceFacade.SaveDoctorDayOff(DocId, date);
        }

        public bool DeleteDoctorDayOff(int DocId, DateTime date)
        {
            ServiceFacade _serviceFacade = new ServiceFacade();
            return _serviceFacade.DeleteDoctorDayOff(DocId, date);
        }

        public List<PatientLocationReportResponse> LocationBasedPatientCount(DateTime startDate, DateTime endDate, int clinicId, int locId, int docId)
        {
            ReportFacade _service = new ReportFacade();
            return _service.LocationBasedPatientCount(startDate, endDate, clinicId,locId,docId);
        }

        public List<FinanceReportResponse> GetFinanceReport(DateTime startDate, DateTime endDate, int clinicId, int locId, int docId)
        {
            ReportFacade _service = new ReportFacade();
            return _service.GetFinanceReport(startDate, endDate, clinicId, locId, docId);
        }

        
    }
}
